import 'package:flutter/material.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

import '../../class/sum/section.dart';
import '../../commont/button.dart';
import '../../model/model.dart';
import '../../model/model_default.dart';
import '../../tool/assets.dart';

class InputView extends SectionView {
  String lefttitle = '';
  String righttitle = '';
  void Function(String) onClick;
  void Function(ChannelModel) onTap;
  void Function(ChannelModel)? onLongPress;
  InputView(
      {super.key,
      required super.title,
      required super.ch_list,
      required this.lefttitle,
      required this.righttitle,
      required this.onClick,
      required this.onTap,
      this.onLongPress});
  @override
  State<InputView> createState() => _InputViewState();
}

class _InputViewState extends SectionViewState<InputView> {
  late final List<ChannelModel> ch_list;

  @override
  Widget buildHeader(BuildContext context) {
    return Positioned(
        top: 5,
        bottom: 5,
        left: 0,
        right: 0,
        child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [widget.lefttitle, widget.righttitle].map(($0) {
              bool select = globalModel.enable &&
                  ($0 == globalModel.input_type ||
                      $0 == globalModel.copy_stype);
              return SizedBox(
                  width: 60,
                  child: kTextButton(
                    name: $0,
                    textColor: globalModel.enable == false
                        ? Color_disEnable
                        : select
                            ? Colors.white
                            : Colors.black,
                    borderColor: globalModel.enable == false
                        ? Color_disEnable
                        : select
                            ? Color_theme
                            : Colors.black,
                    groundColor: select ? Color_theme : Color_bg_view,
                    enable: globalModel.enable,
                    onClick: (p0) => widget.onClick($0),
                  ));
            }).toList()));
  }

  @override
  Widget buildContent(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;
    double w = (screenWidth - 20 * 3 - 20).toDouble() / 4.0;
    double s = GlobalConfig.scaleH.roundDouble(2) - 0.05;
    return SizedBox(
      height: w * 1 / 3.0 * 2 * s + 10 - 0.1,
      child: GridView.extent(

          ///交叉轴最大的尺寸
          maxCrossAxisExtent: w / 3.0 * s,
          crossAxisSpacing: 10.0,
          mainAxisSpacing: 20.0,
          childAspectRatio: 1 / 3.0 * s,
          scrollDirection: Axis.horizontal,
          // physics: const NeverScrollableScrollPhysics(),
          children: (widget.ch_list).map(($0) {
            return GestureDetector(
                onLongPress: () {
                  if (widget.onLongPress != null) {
                    widget.onLongPress!($0);
                  }
                },
                child: kTextButton(
                  name: $0.name,
                  fontSize: 14,
                  textColor: text_color($0),
                  borderColor: border_color($0),
                  groundColor: bg_color($0),
                  enable: $0.enable,
                  onClick: (p0) => widget.onTap($0),
                ));
          }).toList()),
    );
  }
}
